package com.hucheng.common.utils;

import org.springframework.context.ApplicationContext;

import java.util.Map;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-26
 * @Description: 类描述
 **/
public class ContextUtils {
//    private static ApplicationContext applicationContext;
//
//    public static void init(ServletConfig config) {
//        applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
//    }
//
//    public static Object getBean(String key) {
//        return applicationContext.getBean(key);
//    }
//


    private static ApplicationContext applicationContext;

    public static void setApplicationContext(ApplicationContext context) {
        applicationContext = context;
    }

    public static Object getBean(String key) {
        return applicationContext.getBean(key);
    }

    public static <T> Map<String, T> getBean(Class<T> type) {
        return applicationContext.getBeansOfType(type) ;
    }

}
